//
// See the file COPYING for redistribution information.
//

#ifndef __NAIPAX_CONFIG_HPP__
#define __NAIPAX_CONFIG_HPP__

#include <string>
#include <confuse.h>

namespace Naipax {
    /// Configuration file parser
    class Config {
    public:

        /** Constructor
         *
         * @exception Error::CANNOT_INIT_CONFIG
         */
        Config();

        /// Destructor
        ~Config();

        /** Parse configuration in a file.
         *
         * @param pFilename
         * @exception Error::INVALID_ARGUMENT if pFilename is NULL.
         */
        void ParseFile(const char *pFilename);

        
        /** Parse configuration in a file.
         *
         * @param rStr Dumped result
         */
        void Dump(std::string &rStr);
        
        // The following members are transparent. Use with caution.
        std::string mUrlPool;
        std::string mUrlHistoryFile;
        std::string mCrawlerAgent;
        std::string mCrawlerEmail;
        int32_t mCrawlerConnections;
        int32_t mConnectionTimeout;
        int32_t mMaxBandwidth;
        bool mCrawlExternalLinks;
        int32_t mMaxUrlDepth;
        std::string mLogPath;
        bool mUseCookies;
        int32_t mServicePort;
        std::string mAllowDomain;
        std::string mDisallowDomain;
        std::string mAllowUrl;
        std::string mDisallowUrl;
        std::string mAllowContentType;
        std::string mDisallowContentType;
        
    private:
        /// Convert fields in _mpConfuse into STL-based fields.
        void _ConvertOpts();

        cfg_t *_mpConfuse;
    };
};

#endif // __NAIPAX_CONFIG_HPP__
